package com.tengju.bff.interfaces.app.user.assembler;

import com.tengju.bff.interfaces.app.user.vo.UserInfoVO;
import com.tengju.user.application.archives.dto.StarChangeRecordDetailVO;
import com.tengju.user.domain.model.user.StarChangeRecord;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.domain.model.user.UserInfo;

import java.util.Optional;

public class UserInfoAssembler {

    private UserInfoAssembler() {
    }

    public static UserInfoVO userToVO(UserInfo userInfo) {
        if (userInfo == null) {
            return null;
        }
        UserInfoVO userInfoVO = new UserInfoVO();
        userInfoVO.setIdCode(Optional.ofNullable(userInfo.getIdCode()).map(UserIdCode::getValue).orElse(null));
        userInfoVO.setStarRole(userInfo.getStarRole());
        userInfoVO.setStarLevel(userInfo.getStarLevel());
        userInfoVO.setNickName(userInfo.getNickName());
        return userInfoVO;
    }

    public static StarChangeRecordDetailVO starChangeRecordToVO(StarChangeRecord record) {
        StarChangeRecordDetailVO starChangeRecordDetailVO = new StarChangeRecordDetailVO();
        starChangeRecordDetailVO.setOriginStarLevel(record.getBeforeStarLevel());
        starChangeRecordDetailVO.setOriginStarRole(record.getBeforeStarRole());
        starChangeRecordDetailVO.setTargetStarLevel(record.getAfterStarLevel());
        starChangeRecordDetailVO.setTargetStarRole(record.getAfterStarRole());
        starChangeRecordDetailVO.setAuditBy(record.getOperBy());
        starChangeRecordDetailVO.setCreateTime(record.getChangeTime());
        return starChangeRecordDetailVO;
    }
}
